home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_6.lha
/
5_6
/
5_6a.c
next >
Wrap
Text File
|
1993-08-08
|
875b
|
68 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ implement a character queue using
/ a linked list
include <char_queue.h>
include <error.h>
har_queue:: char_queue(int)
rear = front = 0;
har_queue:: ~char_queue()
this->clearQ();
oid char_queue:: enqueue(char c)
if (rear)
{
rear->next = new cQtable;
rear = rear->next;
}
else
front = rear = new cQtable;
rear->next = 0;
rear->c = c;
har char_queue:: dequeue()
if (emptyQ())
error("underflow of character queue");
char c = front->c;
if (front == rear)
{
delete front;
rear = front = 0;
}
else
{
cQtable *old = front;
front = front->next;
delete old;
}
return c;
oid char_queue:: clearQ()
while (front)
{
cQtable *old = front;
front = front->next;
delete old;
}
rear = 0;